Implicit & Explicit localization in ASP.Net

Implicit localization

Implicit localization is used within your markup, and its main advantage is that it allows you to move multiple properties of the same control / object without the explicit reference of each asset. In our localized Hello World chapter, we used it, and saw how we can set the meta: the resource key is the property of a control, and then automatically loads its text property for the resource line in our resource file She goes. Let's expand a bit more on that example, transfer many local properties if you have not done so already, then you should now read the Local Hole World Chapter and create the project from it, because the following example uses it:


<asp:Label runat="server" ID="lblHelloWorld" Text="Hello, world!" Font-Names="Verdana" ForeColor="Blue" meta:resourcekey="lblHelloWorld" />

In three resource files we have created (default, German and Spanish), you can now add two extra rows for each of them with the names "lblHelloWorld.ForeColor" and "lblHelloWorld.Font-Names", and then for Different values ​​can define it. For example, the default label could be blue, the German version might be green, and the Spanish version might be red, and you can also define different font names for each of them. This localization makes it really easy to control because we only have to define the name of the resource line - each property is automatically mapped.

Explicit localization

With clear localization, you choose a specific resource line from your resource file, which is returned to you, and while localization of web controls and other declarative objects, the built-in localization can be useful, obvious localization can be useful in any other The only possible way to work is the situation. Let's see how the above examples will look with clear localization:


<asp:Label runat="server" ID="lblHelloWorld2" Text="<%$ Resources:lblHelloWorld.Text %>" Font-Names="<%$ Resources:lblHelloWorld.Font-Names %>" ForeColor="<%$ Resources:lblHelloWorld.ForeColor %>"  />

We reuse resource rows from our previous example, and as you can see, the markup for a clear localization is a bit more complex and virtualized, which is for mis-localization. The syntax for getting the resource line is like this:


<%$ Resources:[resource class name,]RowName %>

As you can see, we have not specified a resource class name in our example, because we use a local resource. If you use a global resource, then you should specify the name of the class which is the result, which is similar to the thumb rule file name, but without the .resx extension. For example, if you have a global resource file named MyGlobalResources.resx, you will receive a resource like this:


<%$ Resources: MyGlobalResources,NameOfRow %>

As simple as that.